<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<title>通过旧密码修改新密码</title>
<meta charset="utf-8">
<link rel="icon" type="image/png" href="../staticFile/images/common/ico.png" sizes="32x32">
<link type="text/css" rel="stylesheet" href="../staticFile/css/common/common.css">
<link type="text/css" rel="stylesheet" href="../staticFile/css/ventPages/loginRegister.css">
<style type="text/css">
#errMsg{font-size: 16px;margin-top: 8px;color: #e51400;}
.lf button{margin-top: 9px;}
.forget-pwd{width: 80%;
        margin-left: 10%;
        text-align: right;
        margin-top: 8px;}
</style>
<script type="text/javascript" src="../staticFile/js/common/commonUtil.js"></script>
<script type="text/javascript" src="../staticFile/plugins/jquery/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../staticFile/js/common/CheckUtil.js"></script>
<script type="text/javascript" src="../staticFile/plugins/encryption/ventSha1.js"></script>
</head>
<body>
<div class="main-div">
    <div class="logo">
        <a href="/">全民吐<img width="48" height="48" src="../staticFile/images/common/vent.png"/>槽</a>
    </div>
    <div class="short-message-login">
        <strong>通过旧密码修改<span id="myPhone"></span>新密码</strong>
        <div class="lf">
            <input id="oldPwd" type="password" placeholder="请输入旧密码">
            <input id="newPwd" type="password" placeholder="请输入新密码">
        </div>
        <div class="forget-pwd">
            <a href="ventForgetPwd.html">忘记原密码？</a>
        </div>
        <div id="errMsg"></div>
        <div class="lf btn-group">
            <button class="btn" onclick="javascript:history.back();">返回上一页</button>
            <button id="btnUpdatePwd" class="btn">修改密码</button>
        </div>
    </div>
</div>
<script type="text/javascript">
$(function () {
    let me = localStorage.getItem('me');
    if (isNull(me)){
        alert('您还没有登录，请您先登录');
        location.href = 'ventLogin.html';
    }
    me = JSON.parse(me);
    let p = me.userPhone;
    $('#myPhone').text(p.substring(0,1) + '******' + p.substring(7,12));
    $('#btnUpdatePwd').click(function () {
        sureModifyPwd(this);
    });
});
function sureModifyPwd(btnSureObj) {
    let newPwd = V('newPwd'),oldPwd = V('oldPwd');
    if (isNull(oldPwd)) {
        setErrMsg('手机号不能为空');
        btnSureObj.disabled = false;
        return;
    }
    if (isNull(newPwd)) {
        setErrMsg('新密码不能为空');
        btnSureObj.disabled = false;
        return;
    }
    if(!confirm('您确认要修改密码吗？')){
        btnSureObj.disabled = false;
        return;
    }
    let shaObj = new jsSHA("SHA-1", "TEXT");
    shaObj.update(newPwd);
    newPwd = shaObj.getHash("HEX");
    $.ajax({
        type: "POST",
        url: '/ventUserIndex/modifyPwdByOld',
        data:{oldPwd: oldPwd,newPwd: newPwd},
        dataType: 'json',
        success: function(modifyResult) {
            let ms = modifyResult.status;
            if(ms == '1'){
                alert('修改密码时出错');
            }else if(ms == '2'){
                alert('未获取到旧密码');
            }else if(ms == '-1'){
                alert('登录失效，请重新登录');
                sessionStorage.setItem('backUrl','modifyPwdByOld');
                location.href = 'ventLogin.html';
            }else if(ms == '4'){
                alert('未获取到新密码');
            }else if(ms == '0'){
                alert('密码修改成功,快去登录吧');
                window.location.href = 'ventLogin.html';
            }else {
                alert('密码修改失败');
            }
            btnSureObj.disabled = false;
        },
        error: function() {
            alert('当前系统繁忙,请稍后再获取验证码');
            btnSureObj.disabled = false;
        }
    });
}
</script>
</body>
</html>